package com.tc.mongo;

import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.io.*;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 格式构造器
 *
 * @author treey.qian
 */
public class CommonUtil {

    /**
     * 连接符日期格式
     */
    public static final String CONNECTION_SYMBOL_DATEFORMAT = "yyyy-MM-dd HH:mm:ss";
    /**
     * 无连接符日期格式
     */
    public static final String NO_CONNECTION_SYMBOL_DATEFORMAT = "yyyyMMddHHmmss";

    /**
     * 连接符年份格式
     */
    public static final String CONNECTION_SYMBOL_YEARFORMAT = "yyyy-MM-dd";

    /**
     * 无连接符年份格式
     */
    public static final String NO_CONNECTION_SYMBOL_YEARFORMAT = "yyyyMMdd";

    /**
     * 支付机构编码
     */
    public static final String ORGANIZATION_CODE = "Z11933000018";

    /**
     * 键值对(文件头信息:文件类型)
     */
    private final static Map<String, String> FILE_TYPE_MAP = new HashMap<>();

    /**
     * 键值对(文件类型:content-type)
     */
    private final static Map<String, String> CONTENT_TYPE_MAP = new HashMap<>();

    static {
        initFileTypeMap();
        initContentTypeMap();
    }

    /**
     * 得到指定格式的日期
     *
     * @param date    日期值
     * @param pattern 输出格式
     * @return
     */
    public static String getDateOfFormat(Date date, String pattern) {
        if (date == null || pattern == null || pattern.trim().equals("")) {
            throw new IllegalArgumentException("date(" + date + ") 或者 pattern(" + pattern + ")不合法");
        }
        return new SimpleDateFormat(pattern).format(date);
    }

    /**
     * 筛选出可录入的文件 infoCreateDate<fileCreateDate ==> true
     *
     * @param infoCreateDate 数据库记录中已处理前置机文件创建时间
     * @param fileCreateDate 前置机中新文件创建的时间
     * @return
     */
    public static boolean isInclude(Date infoCreateDate, Date fileCreateDate) {
        if (infoCreateDate == null || fileCreateDate == null) {
            throw new IllegalArgumentException("infoCreateDate(" + infoCreateDate + ") 或 fileCreateDate(" + fileCreateDate + ")不合法");
        }
        return infoCreateDate.compareTo(fileCreateDate) < 0;
    }

    /**
     * 根据日期格式将日期字符串转换为日期
     *
     * @param dateValue 日期字符串
     * @param pattern   日期格式
     * @return
     */
    public static Date parseDateOfFormatFromDateValue(String dateValue, String pattern) throws ParseException {
        if (dateValue == null || dateValue.trim().equals("") || pattern == null || pattern.trim().equals("")) {
            throw new IllegalArgumentException("dateValue(" + dateValue + ") 或 pattern(" + pattern + ")不合法");
        }
        return new SimpleDateFormat(pattern).parse(dateValue);
    }

    /**
     * 12支付机构编码+生成28位随机码 （14位数字+8位时间戳+6位序列）
     *
     * @param number 系统统一记录编号
     * @return
     */

    public static String getTransSerialNumber(long number) {
        StringBuffer stringBuffer = new StringBuffer().append(ORGANIZATION_CODE).append(number)
                .append(CommonUtil.getDateOfFormat(new Date(), NO_CONNECTION_SYMBOL_YEARFORMAT))
                .append(System.currentTimeMillis());
        return stringBuffer.toString();
    }

    /**
     * 得到指定时间前的时间戳（单位按分钟计算）
     *
     * @param minutes 指定时间值
     * @return
     */
    public static Date getTimestampBefore(int minutes) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MINUTE, minutes);
        return calendar.getTime();
    }

    /**
     * 输出异常信息
     *
     * @param exception 异常
     * @return
     */
    public static String getTextFromException(Exception exception) {
        if (exception == null) {
            throw new IllegalArgumentException("exception不能为null");
        }
        String text;
        try {
            StringWriter stringWriter = new StringWriter();
            exception.printStackTrace(new PrintWriter(stringWriter, true));
            text = stringWriter.toString();
            if (stringWriter != null)
                stringWriter.close();
        } catch (IOException e) {
            text = "捕获异常信息出错" + e.getMessage();
            e.printStackTrace();
        }
        return text;
    }

    /**
     * 得到当前路径下的类名
     *
     * @return
     */
    public static String getCurrentClassName() {
        String className = "class not exit";
        try {
            StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
            if (stackTraceElements != null && stackTraceElements.length >= 2) {
                className = stackTraceElements[1].getClassName();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return className;
    }

    /**
     * 得到当前路径下的方法名
     *
     * @return
     */
    public static String getCurrentMethodName() {
        String methodName = "method not exit";
        try {
            StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
            if (stackTraceElements != null && stackTraceElements.length >= 2) {
                methodName = stackTraceElements[1].getMethodName();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return methodName;
    }

    /**
     * 正则表达式
     *
     * @param param         参数
     * @param patternFormat 验证规则
     * @return
     */
    public static boolean validParams(String param, String patternFormat) {
        if (param == null || param.trim().equals("") || patternFormat == null || patternFormat.trim().equals("")) {
            throw new IllegalArgumentException("param(" + param + ") 或 patternFormat(" + patternFormat + ")不合法");
        }
        Pattern pattern = Pattern.compile(patternFormat);
        Matcher matcher = pattern.matcher(param);
        return matcher.matches();
    }

    /**
     * 数据元素枚举
     *
     * @param objs      数组
     * @param paramName 数组名字
     * @return
     */
    public static String arraysIterator(Object[] objs, String paramName) {
        if (objs == null || objs.length == 0) {
            throw new IllegalArgumentException("objs(" + objs + ")不合法");
        }
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < objs.length; i++) {
            builder.append(paramName + "[" + i + "]=" + objs[i]);
        }
        return builder.toString();
    }

    /**
     * 记录唯一标识生成器
     *
     * @return
     */
    public static String getUuid() {
        return UUID.randomUUID().toString().trim().replaceAll("-", "");
    }

    /**
     * 回滚当前事务
     */
    public static void rollback() {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
    }

    /**
     * 得到当前服务器路径
     *
     * @return
     */
    public static String getApplicationContextPath() {
        return Thread.currentThread().getContextClassLoader().getResource(File.separator).toString();
    }

    /**
     * 文件类型是否存在
     *
     * @param fileType 文件类型
     * @return
     */
    public static boolean isExist(String fileType) {
        if (fileType == null || fileType.trim().equals("")) {
            throw new IllegalArgumentException("fileType(" + fileType + ")不正确");
        }
        boolean isExist = false;
        for (String value : FILE_TYPE_MAP.values()) {
            if (fileType.trim().toLowerCase().equals(value.toLowerCase().trim())) {
                isExist = true;
                break;
            }
        }
        return isExist;
    }

    /**
     * 得到指定文件类型
     *
     * @param fileContent 文件内容（Base64未编码前）
     * @return
     * @throws Exception
     */
    public static String getFileType(String fileContent) {
        if (fileContent == null || fileContent.trim().equals("")) {
            throw new IllegalArgumentException("fileContent" + fileContent + "不正确");
        }
        //构造文件头信息字节数组
        byte[] fileHeadBytes = new byte[4];
        //获得编码后的字节
        ByteArrayInputStream byteArrayInputStream = null;//new ByteArrayInputStream(Base64.decode(fileContent));
        //将文件头信息读入文件头信息字节数组
        byteArrayInputStream.read(fileHeadBytes, 0, fileHeadBytes.length);
        //构造文件头文件
        String fileHeadCode = fileHeadBytesToHexString(fileHeadBytes);
        //构造文件后缀
        StringBuilder builder = new StringBuilder();
        for (Map.Entry<String, String> entry : FILE_TYPE_MAP.entrySet()) {
            //获取文件头文件全量编码
            String fileAllHeadCode = entry.getKey().toLowerCase();
            if (fileAllHeadCode.startsWith(fileHeadCode) || fileHeadCode.startsWith(fileAllHeadCode)) {
                builder.append(entry.getValue().toLowerCase());
                break;
            }
        }
        return builder.toString();
    }


    /**
     * 根据文件后缀名得到content-type
     *
     * @param filePostfix 文件后缀
     * @return
     * @throws Exception
     */
    public static String getContentType(String filePostfix) {
        if (filePostfix == null || !filePostfix.startsWith(".")) {
            throw new IllegalArgumentException("filePostfix(" + filePostfix + ")格式不正确");
        }
        return CONTENT_TYPE_MAP.get(filePostfix);
    }

    /**
     * 构造需要输出的字段数组
     *
     * @param originalFields    原始字段数组
     * @param excludeFieldNames 移除字段名数组
     * @return
     */
    public static List<String> convertFileds(Field[] originalFields, String[] excludeFieldNames) {
        if (originalFields == null || originalFields.length == 0 || excludeFieldNames == null || excludeFieldNames.length == 0) {
            throw new IllegalArgumentException("originalFields(" + originalFields + ") 或 excludeFieldNames(" + excludeFieldNames + ")不合法");
        }
        List<String> includeFieldNameList = new ArrayList<>();
        List<Field> originalFieldList = Arrays.asList(originalFields);
        List<String> excludeFieldNameList = Arrays.asList(excludeFieldNames);
        for (Field field : originalFieldList) {
            String fieldName = field.getName();
            if (!excludeFieldNameList.contains(fieldName)) {
                includeFieldNameList.add(fieldName);
            }
        }
        return includeFieldNameList;
    }

    /**
     * 得到content-type集合
     *
     * @return
     */
    public static Map<String, String> getContentTypeMap() {
        return CONTENT_TYPE_MAP;
    }

    /**
     * 得到文件类型集合
     *
     * @return
     */
    public static Map<String, String> getFileTypeMap() {
        return FILE_TYPE_MAP;
    }

    /**
     * 获得文件头信息
     *
     * @param fileHeadBytes 文件头信息字节（4B）
     * @return
     */
    private static String fileHeadBytesToHexString(byte[] fileHeadBytes) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < fileHeadBytes.length; i++) {
            // 以十六进制（基数 16）无符号整数形式 返回一个整数参数的字符串表示形式，并转换为大写
            String hexText = Integer.toHexString(fileHeadBytes[i] & 0xFF);
            if (hexText.length() < 2) {
                builder.append(0);
            }
            builder.append(hexText);
        }
        return builder.toString().toLowerCase();
    }

    /**
     * 初始化文件类型集合
     */
    private static void initFileTypeMap() {
        FILE_TYPE_MAP.put("ffd8ffe000104a464946", "jpg"); //JPEG (jpg)
        FILE_TYPE_MAP.put("89504e470d0a1a0a0000", "png"); //PNG (png)
        FILE_TYPE_MAP.put("47494638396126026f01", "gif"); //GIF (gif)
        FILE_TYPE_MAP.put("49492a00227105008037", "tif"); //TIFF (tif)
        FILE_TYPE_MAP.put("424d228c010000000000", "bmp"); //16色位图(bmp)
        FILE_TYPE_MAP.put("424d8240090000000000", "bmp"); //24位位图(bmp)
        FILE_TYPE_MAP.put("424d8e1b030000000000", "bmp"); //256色位图(bmp)
        FILE_TYPE_MAP.put("41433130313500000000", "dwg"); //CAD (dwg)
        FILE_TYPE_MAP.put("3c21444f435459504520", "html"); //HTML (html)
        FILE_TYPE_MAP.put("3c21646f637479706520", "htm"); //HTM (htm)
        FILE_TYPE_MAP.put("48544d4c207b0d0a0942", "css"); //css
        FILE_TYPE_MAP.put("696b2e71623d696b2e71", "js"); //js
        FILE_TYPE_MAP.put("7b5c727466315c616e73", "rtf"); //Rich Text Format (rtf)
        FILE_TYPE_MAP.put("38425053000100000000", "psd"); //Photoshop (psd)
        FILE_TYPE_MAP.put("46726f6d3a203d3f6762", "eml"); //Email [Outlook Express 6] (eml)
        FILE_TYPE_MAP.put("d0cf11e0a1b11ae10000", "doc"); //MS Excel 注意：word、msi 和 excel的文件头一样
        FILE_TYPE_MAP.put("d0cf11e0a1b11ae10000", "vsd"); //Visio 绘图
        FILE_TYPE_MAP.put("5374616E64617264204A", "mdb"); //MS Access (mdb)
        FILE_TYPE_MAP.put("252150532D41646F6265", "ps");
        FILE_TYPE_MAP.put("255044462d312e350d0a", "pdf"); //Adobe Acrobat (pdf)
        FILE_TYPE_MAP.put("2e524d46000000120001", "rmvb"); //rmvb/rm相同
        FILE_TYPE_MAP.put("464c5601050000000900", "flv"); //flv与f4v相同
        FILE_TYPE_MAP.put("00000020667479706d70", "mp4");
        FILE_TYPE_MAP.put("49443303000000002176", "mp3");
        FILE_TYPE_MAP.put("000001ba210001000180", "mpg"); //
        FILE_TYPE_MAP.put("3026b2758e66cf11a6d9", "wmv"); //wmv与asf相同
        FILE_TYPE_MAP.put("52494646e27807005741", "wav"); //Wave (wav)
        FILE_TYPE_MAP.put("52494646d07d60074156", "avi");
        FILE_TYPE_MAP.put("4d546864000000060001", "mid"); //MIDI (mid)
        FILE_TYPE_MAP.put("504b0304140000000800", "zip");
        FILE_TYPE_MAP.put("526172211a0700cf9073", "rar");
        FILE_TYPE_MAP.put("235468697320636f6e66", "ini");
        FILE_TYPE_MAP.put("504b03040a0000000000", "jar");
        FILE_TYPE_MAP.put("4d5a9000030000000400", "exe");//可执行文件
        FILE_TYPE_MAP.put("3c25402070616765206c", "jsp");//jsp文件
        FILE_TYPE_MAP.put("4d616e69666573742d56", "mf");//MF文件
        FILE_TYPE_MAP.put("3c3f786d6c2076657273", "xml");//xml文件
        FILE_TYPE_MAP.put("494e5345525420494e54", "sql");//xml文件
        FILE_TYPE_MAP.put("7061636b616765207765", "java");//java文件
        FILE_TYPE_MAP.put("406563686f206f66660d", "bat");//bat文件
        FILE_TYPE_MAP.put("1f8b0800000000000000", "gz");//gz文件
        FILE_TYPE_MAP.put("6c6f67346a2e726f6f74", "properties");//bat文件
        FILE_TYPE_MAP.put("cafebabe0000002e0041", "class");//bat文件
        FILE_TYPE_MAP.put("49545346030000006000", "chm");//bat文件
        FILE_TYPE_MAP.put("04000000010000001300", "mxp");//bat文件
        FILE_TYPE_MAP.put("504b0304140006000800", "docx");//docx文件
        FILE_TYPE_MAP.put("d0cf11e0a1b11ae10000", "wps");//WPS文字wps、表格et、演示dps都是一样的
        FILE_TYPE_MAP.put("6431303a637265617465", "torrent");
        FILE_TYPE_MAP.put("6D6F6F76", "mov"); //Quicktime (mov)
        FILE_TYPE_MAP.put("FF575043", "wpd"); //WordPerfect (wpd)
        FILE_TYPE_MAP.put("CFAD12FEC5FD746F", "dbx"); //Outlook Express (dbx)
        FILE_TYPE_MAP.put("2142444E", "pst"); //Outlook (pst)
        FILE_TYPE_MAP.put("AC9EBD8F", "qdf"); //Quicken (qdf)
        FILE_TYPE_MAP.put("E3828596", "pwl"); //Windows Password (pwl)
        FILE_TYPE_MAP.put("2E7261FD", "ram"); //Real Audio (ram)
    }

    /**
     * 初始化contenttype集合
     */
    private static void initContentTypeMap() {
        CONTENT_TYPE_MAP.put(".ez", "application/andrew-inset");
        CONTENT_TYPE_MAP.put(".hqx", "application/mac-binhex40");
        CONTENT_TYPE_MAP.put(".cpt", "application/mac-compactpro");
        CONTENT_TYPE_MAP.put(".doc", "application/msword");
        CONTENT_TYPE_MAP.put(".bin", "application/octet-stream");
        CONTENT_TYPE_MAP.put(".dms", "application/octet-stream");
        CONTENT_TYPE_MAP.put(".lha", "application/octet-stream");
        CONTENT_TYPE_MAP.put(".lzh", "application/octet-stream");
        CONTENT_TYPE_MAP.put(".exe", "application/octet-stream");
        CONTENT_TYPE_MAP.put(".class", "application/octet-stream");
        CONTENT_TYPE_MAP.put(".so", "application/octet-stream");
        CONTENT_TYPE_MAP.put(".dll", "application/octet-stream");
        CONTENT_TYPE_MAP.put(".oda", "application/oda");
        CONTENT_TYPE_MAP.put(".pdf", "application/pdf");
        CONTENT_TYPE_MAP.put(".ai", "application/postscript");
        CONTENT_TYPE_MAP.put(".eps", "application/postscript");
        CONTENT_TYPE_MAP.put(".ps", "application/postscript");
        CONTENT_TYPE_MAP.put(".smi", "application/smil");
        CONTENT_TYPE_MAP.put(".smil", "application/smil");
        CONTENT_TYPE_MAP.put(".mif", "application/vnd.mif");
        CONTENT_TYPE_MAP.put(".xls", "application/vnd.ms-excel");
        CONTENT_TYPE_MAP.put(".ppt", "application/vnd.ms-powerpoint");
        CONTENT_TYPE_MAP.put(".wbxml", "application/vnd.wap.wbxml");
        CONTENT_TYPE_MAP.put(".wmlc", "application/vnd.wap.wmlc");
        CONTENT_TYPE_MAP.put(".wmlsc", "application/vnd.wap.wmlscriptc");
        CONTENT_TYPE_MAP.put(".bcpio", "application/x-bcpio");
        CONTENT_TYPE_MAP.put(".vcd", "application/x-cdlink");
        CONTENT_TYPE_MAP.put(".pgn", "application/x-chess-pgn");
        CONTENT_TYPE_MAP.put(".cpio", "application/x-cpio");
        CONTENT_TYPE_MAP.put(".csh", "application/x-csh");
        CONTENT_TYPE_MAP.put(".dcr", "application/x-director");
        CONTENT_TYPE_MAP.put(".dir", "application/x-director");
        CONTENT_TYPE_MAP.put(".dxr", "application/x-director");
        CONTENT_TYPE_MAP.put(".dvi", "application/x-dvi");
        CONTENT_TYPE_MAP.put(".spl", "application/x-futuresplash");
        CONTENT_TYPE_MAP.put(".gtar", "application/x-gtar");
        CONTENT_TYPE_MAP.put(".hdf", "application/x-hdf");
        CONTENT_TYPE_MAP.put(".js", "application/x-javascript");
        CONTENT_TYPE_MAP.put(".skp", "application/x-koan");
        CONTENT_TYPE_MAP.put(".skd", "application/x-koan");
        CONTENT_TYPE_MAP.put(".skt", "application/x-koan");
        CONTENT_TYPE_MAP.put(".skm", "application/x-koan");
        CONTENT_TYPE_MAP.put(".latex", "application/x-latex");
        CONTENT_TYPE_MAP.put(".nc", "application/x-netcdf");
        CONTENT_TYPE_MAP.put(".cdf", "application/x-netcdf");
        CONTENT_TYPE_MAP.put(".sh", "application/x-sh");
        CONTENT_TYPE_MAP.put(".shar", "application/x-shar");
        CONTENT_TYPE_MAP.put(".swf", "application/x-shockwave-flash");
        CONTENT_TYPE_MAP.put(".sit", "application/x-stuffit");
        CONTENT_TYPE_MAP.put(".sv4cpio", "application/x-sv4cpio");
        CONTENT_TYPE_MAP.put(".sv4crc", "application/x-sv4crc");
        CONTENT_TYPE_MAP.put(".tar", "application/x-tar");
        CONTENT_TYPE_MAP.put(".tcl", "application/x-tcl");
        CONTENT_TYPE_MAP.put(".tex", "application/x-tex");
        CONTENT_TYPE_MAP.put(".texinfo", "application/x-texinfo");
        CONTENT_TYPE_MAP.put(".texi", "application/x-texinfo");
        CONTENT_TYPE_MAP.put(".t", "application/x-troff");
        CONTENT_TYPE_MAP.put(".tr", "application/x-troff");
        CONTENT_TYPE_MAP.put(".roff", "application/x-troff");
        CONTENT_TYPE_MAP.put(".man", "application/x-troff-man");
        CONTENT_TYPE_MAP.put(".me", "application/x-troff-me");
        CONTENT_TYPE_MAP.put(".ms", "application/x-troff-ms");
        CONTENT_TYPE_MAP.put(".ustar", "application/x-ustar");
        CONTENT_TYPE_MAP.put(".src", "application/x-wais-source");
        CONTENT_TYPE_MAP.put(".xhtml", "application/xhtml+xml");
        CONTENT_TYPE_MAP.put(".xht", "application/xhtml+xml");
        CONTENT_TYPE_MAP.put(".zip", "application/zip");
        CONTENT_TYPE_MAP.put(".au", "audio/basic");
        CONTENT_TYPE_MAP.put(".snd", "audio/basic");
        CONTENT_TYPE_MAP.put(".mid", "audio/midi");
        CONTENT_TYPE_MAP.put(".midi", "audio/midi");
        CONTENT_TYPE_MAP.put(".kar", "audio/midi");
        CONTENT_TYPE_MAP.put(".mpga", "audio/mpeg");
        CONTENT_TYPE_MAP.put(".mp2", "audio/mpeg");
        CONTENT_TYPE_MAP.put(".mp3", "audio/mpeg");
        CONTENT_TYPE_MAP.put(".aif", "audio/x-aiff");
        CONTENT_TYPE_MAP.put(".aiff", "audio/x-aiff");
        CONTENT_TYPE_MAP.put(".aifc", "audio/x-aiff");
        CONTENT_TYPE_MAP.put(".m3u", "audio/x-mpegurl");
        CONTENT_TYPE_MAP.put(".ram", "audio/x-pn-realaudio");
        CONTENT_TYPE_MAP.put(".rm", "audio/x-pn-realaudio");
        CONTENT_TYPE_MAP.put(".rpm", "audio/x-pn-realaudio-plugin");
        CONTENT_TYPE_MAP.put(".ra", "audio/x-realaudio");
        CONTENT_TYPE_MAP.put(".wav", "audio/x-wav");
        CONTENT_TYPE_MAP.put(".pdb", "chemical/x-pdb");
        CONTENT_TYPE_MAP.put(".xyz", "chemical/x-xyz");
        CONTENT_TYPE_MAP.put(".bmp", "image/bmp");
        CONTENT_TYPE_MAP.put(".gif", "image/gif");
        CONTENT_TYPE_MAP.put(".ief", "image/ief");
        CONTENT_TYPE_MAP.put(".jpeg", "image/jpeg");
        CONTENT_TYPE_MAP.put(".jpg", "image/jpeg");
        CONTENT_TYPE_MAP.put(".jpe", "image/jpeg");
        CONTENT_TYPE_MAP.put(".png", "image/png");
        CONTENT_TYPE_MAP.put(".tiff", "image/tiff");
        CONTENT_TYPE_MAP.put(".tif", "image/tiff");
        CONTENT_TYPE_MAP.put(".djvu", "image/vnd.djvu");
        CONTENT_TYPE_MAP.put(".djv", "image/vnd.djvu");
        CONTENT_TYPE_MAP.put(".wbmp", "image/vnd.wap.wbmp");
        CONTENT_TYPE_MAP.put(".ras", "image/x-cmu-raster");
        CONTENT_TYPE_MAP.put(".pnm", "image/x-portable-anymap");
        CONTENT_TYPE_MAP.put(".pbm", "image/x-portable-bitmap");
        CONTENT_TYPE_MAP.put(".pgm", "image/x-portable-graymap");
        CONTENT_TYPE_MAP.put(".ppm", "image/x-portable-pixmap");
        CONTENT_TYPE_MAP.put(".rgb", "image/x-rgb");
        CONTENT_TYPE_MAP.put(".xbm", "image/x-xbitmap");
        CONTENT_TYPE_MAP.put(".xpm", "image/x-xpixmap");
        CONTENT_TYPE_MAP.put(".xwd", "image/x-xwindowdump");
        CONTENT_TYPE_MAP.put(".igs", "model/iges");
        CONTENT_TYPE_MAP.put(".iges", "model/iges");
        CONTENT_TYPE_MAP.put(".msh", "model/mesh");
        CONTENT_TYPE_MAP.put(".mesh", "model/mesh");
        CONTENT_TYPE_MAP.put(".silo", "model/mesh");
        CONTENT_TYPE_MAP.put(".wrl", "model/vrml");
        CONTENT_TYPE_MAP.put(".vrml", "model/vrml");
        CONTENT_TYPE_MAP.put(".css", "text/css");
        CONTENT_TYPE_MAP.put(".html", "text/html");
        CONTENT_TYPE_MAP.put(".htm", "text/html");
        CONTENT_TYPE_MAP.put(".asc", "text/plain");
        CONTENT_TYPE_MAP.put(".txt", "text/plain");
        CONTENT_TYPE_MAP.put(".rtx", "text/richtext");
        CONTENT_TYPE_MAP.put(".rtf", "text/rtf");
        CONTENT_TYPE_MAP.put(".sgml", "text/sgml");
        CONTENT_TYPE_MAP.put(".sgm", "text/sgml");
        CONTENT_TYPE_MAP.put(".tsv", "text/tab-separated-values");
        CONTENT_TYPE_MAP.put(".wml", "text/vnd.wap.wml");
        CONTENT_TYPE_MAP.put(".wmls", "text/vnd.wap.wmlscript");
        CONTENT_TYPE_MAP.put(".etx", "text/x-setext");
        CONTENT_TYPE_MAP.put(".xsl", "text/xml");
        CONTENT_TYPE_MAP.put(".xml", "text/xml");
        CONTENT_TYPE_MAP.put(".mpeg", "video/mpeg");
        CONTENT_TYPE_MAP.put(".mpg", "video/mpeg");
        CONTENT_TYPE_MAP.put(".mpe", "video/mpeg");
        CONTENT_TYPE_MAP.put(".qt", "video/quicktime");
        CONTENT_TYPE_MAP.put(".mov", "video/quicktime");
        CONTENT_TYPE_MAP.put(".mxu", "video/vnd.mpegurl");
        CONTENT_TYPE_MAP.put(".avi", "video/x-msvideo");
        CONTENT_TYPE_MAP.put(".movie", "video/x-sgi-movie");
        CONTENT_TYPE_MAP.put(".ice", "x-conference/x-cooltalk");
    }
}
